from typing import List
from common.enum.strategy_group_enum import StrategyGroup
from common.enum.strategy_type_enum import StrategyType
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_assessment import RiskAssessment
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_stock_day import StrategyStockDay
from service.strategy.base_strategy import BaseStrategy

class VolumeIncreaseStrategy(BaseStrategy):
    """
    关注策略：判断某个股票的成交量比前一天多50%以上，
    每多10%则得额外一分。
    """

    def analyze(self, trade_info_list: List[StrategyStockDay]) -> RiskAssessment:
        """
        分析某个股票当天的成交量是否比前一天多50%以上，
        每多10%则增加额外的得分。
        """
        node_point = 0
        description = ""

        # 确保至少有2天的交易数据
        if len(trade_info_list) >= 2:
            # 获取最近两天的交易数据
            today = trade_info_list[-1]
            yesterday = trade_info_list[-2]

            # 判断当天的成交量是否比前一天多50%以上
            if today.vol > yesterday.vol * 1.5:
                # 计算成交量增长百分比
                volume_increase_percentage = (today.vol - yesterday.vol) / yesterday.vol * 100
                additional_points = (volume_increase_percentage - 50) // 10  # 每多10%增加1分
                node_point += 1 + int(additional_points)  # 初始得分为1，加上多出的得分
                description += f"Volume increased by {volume_increase_percentage:.2f}% compared to yesterday. "

        return RiskAssessment(
            stock_code=trade_info_list[0].stock_code,
            description=description,
            config=self.strategyConfig(),
            node_point=node_point,
        )

    def strategyConfig(self) -> StrategyInfoMetadata:
        """
        返回策略的配置
        """
        return StrategyInfoMetadata(
            strategy_code="volume_increase",
            strategy_name="成交量增加策略",
            strategy_group=StrategyGroup.ATTENTION,  # 关注型策略
            strategy_type=StrategyType.VOLUME,  # 根据成交量类型
            analysis_day=2,
            strategy_level=2,
        )
